import * as systemService from '../../services/system';
import {routerRedux} from 'dva/router';

export default {
  namespace: 'resourceManager',
  state: {
    resources: [],
    selectRows:[],
  },
  reducers: {
    updateResources(state, {payload}) {
      const newstate = state;
      newstate.resources = payload;
      return newstate;
    },
    updateSelectRows(state, {payload}) {
      const newstate = state;
      newstate.selectRows = payload;
      return newstate;
    },
  },
  effects: {
    *getAllResources({payload}, {call, put}) {
      const {data} = yield call(systemService.getAllResources);
      yield put({type: 'updateResources', payload: data});
    },
    *deleteResources({payload}, {call, put}) {
      yield call(systemService.deleteResources,payload);
      yield put({type: 'getAllResources'});
    },
    *addResource({payload}, {call, put}) {
      const {data} = yield call(systemService.addResource,payload);
      yield put({type: 'getAllResources'});
      const datas=new Array();
      datas.push(data);
      yield put({type: 'updateSelectRows',payload:datas});
    },
    *updateSelectRow({payload}, {put}) {
      yield put({type: 'updateSelectRows',payload:payload});
    },
  },
  subscriptions: {
  },

}
